package com.test.JVM;

import java.util.Collections;
import java.util.HashMap;
import java.util.WeakHashMap;

public class WeakHashMapDemo {
    public static void main(String[] args) {
        myHashMap();
        System.out.println("======================");
        myWeakHashMap();
    }
    private static void myHashMap(){
        HashMap map = new HashMap();
        Integer key = new Integer(1);
        String value = "hashmap";
        map.put(key,value);
        System.out.println(map);

        key = null;
        System.out.println(map);

        System.gc();
        System.out.println(map+"\t"+map.size());
    }

    private static void myWeakHashMap() {
        WeakHashMap map = new WeakHashMap();
        Integer key = new Integer(2);
        String value = "weakhashmap";
        map.put(key,value);
        System.out.println(map);

        key = null;
        System.out.println(map);

        System.gc();
        System.out.println(map+"\t"+map.size());
    }
}
